<?php
class chkLogin extends Controller{
    function __construct(){
        parent::__construct();
    }
    /*   
     */
    public function index($username = '',$userpwd = ''){
        if(isset($_POST['username'])){
            $username = $_POST['username'];
        }
        if(isset($_POST['userpwd'])){
            $userpwd = $_POST['userpwd'];
        }      
        $result = $this->chkUser($username,$userpwd);
        $this->T->assign("loginResult",$result);
        $this->T->load("login_result.html");
    }
    public function chkCookies(){
        if(isset($_COOKIE['username'])&&isset($_COOKIE['userpwd'])){
            $username = $_COOKIE['username'];
            $pwd = $_COOKIE['userpwd'];
            $flag = $this->chkUser($username,$userpwd);
            return $flag;
        }
    }
    /*
     *call chkUserLogin() in User model
     *param username,userpwd
     *return success:true  fail:USER_LOGIN_ERROR
     */
    private function chkUser($username,$userpwd){
       // $sql = "select * from littleoj_user where user_name = $username and $userpwd = userpwd";
        $this->db = $this->load->model('User');
        $result = $this->db->chkUserLogin($username,$userpwd);
        var_dump($result);
        return $result;
    }
}